package hcom.model.member.action;

import java.util.List;

import hcom.model.member.bean.MemberBean;
import hcom.model.member.dao.MemberDao;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class MemberAction extends ActionSupport implements Preparable, ModelDriven<MemberBean> {
	private MemberBean memberBean;
	private List<MemberBean> list;
	
	private MemberBean memberView;
	
	private MemberDao dao = MemberDao.getInstance();
	
	public String getAdminList() throws Exception {
		list = dao.getAdminList();
		memberBean.setTotalCount(dao.getAdminCount());
		
		return SUCCESS;
	}
	
	public String adminReg() throws Exception {
		dao.insertAdmin(memberBean);
		
		return SUCCESS;
	}
	
	public String adminModifyForm() throws Exception {
		memberView = dao.getAdminDetail(memberBean.getMem_seq());
		
		return SUCCESS;
	}
	
	public String adminModify() throws Exception {
		dao.updateAdmin(memberBean);
		
		return SUCCESS;
	}
	
	public String adminDelete() throws Exception {
		dao.deleteAdmin(memberBean.getMem_seq());
		
		return SUCCESS;
	}
	
	public String getLeaderList() throws Exception {
		list = dao.getLeaderList();
		memberBean.setTotalCount(dao.getLeaderCount());
		
		return SUCCESS;
	}

	public String leaderReg() throws Exception {
		dao.insertLeader(memberBean);
		
		return SUCCESS;
	}
	
	public String leaderModifyForm() throws Exception {
		System.out.println("****"+memberBean.getLeader_seq());
		memberView = dao.getLeaderDetail(memberBean.getLeader_seq());
		
		return SUCCESS;
	}
	
	public String leaderModify() throws Exception {
		System.out.println("****"+memberBean.getLeader_seq());
		dao.updateLeader(memberBean);
		
		return SUCCESS;
	}
	
	public String leaderDelete() throws Exception{
		System.out.println("****"+memberBean.getLeader_seq());
		dao.deleteLeader(memberBean.getLeader_seq());
		
		return SUCCESS;
	}
	
	@Override
	public MemberBean getModel() {
		// TODO Auto-generated method stub
		return memberBean;
	}

	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		memberBean = new MemberBean();
	}

	public MemberBean getMemberBean() {
		return memberBean;
	}

	public void setMemberBean(MemberBean memberBean) {
		this.memberBean = memberBean;
	}

	public List<MemberBean> getList() {
		return list;
	}

	public void setList(List<MemberBean> list) {
		this.list = list;
	}

	public MemberBean getMemberView() {
		return memberView;
	}

	public void setMemberView(MemberBean memberView) {
		this.memberView = memberView;
	}

	
}
